﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void ClickChangePassword(object sender, EventArgs e)
    {
        if (!(string.IsNullOrEmpty(txtPassword.Text)))
        {
            if (txtPassword.Text == txtVerifyPassword.Text)
            {
                int result = DataBase.Users.UpdatePassword(int.Parse(Session["userID"].ToString()), txtOldPassword.Text, txtPassword.Text);
                if(result == -1)
                    lblErrorMessage.Text = "Incorrect Current Password";
                else if(result == 0)
                    lblErrorMessage.Text = "Internal Server Error. Contact Suppot";
                else
                    lblSuccess.Text = "Passwords Succesfully Changed!";
                
            }
            else
            {
                lblErrorMessage.Text = "Passwords do not match";
            }
        }
        else
        {
            lblErrorMessage.Text = "Password cannot be left empty";

        }
        

    }
}